﻿import com.gamemeal.navigation.INavigation;
import com.mixmedia.mx.AbstractEventDispatcher;

import events.NavigationEvent;
/**
 * @author Colin
 */
class com.gamemeal.navigation.Navigation extends AbstractEventDispatcher implements INavigation{
	static private var ins:Navigation;
	static public function instance():Navigation{
		if(ins==null)ins = new Navigation();
		return ins;
	}

	public var currentSection : String;
	public var history:Array;

	private function Navigation(){
		history = new Array();		
	}

	public function changeSection(sectionId:String,target:String):Void{
		history.push(currentSection);
		currentSection = sectionId;
		dispatchEvent(new NavigationEvent(this,NavigationEvent.CHANGE,sectionId,target));
	}

	public function getCurrentSection() : String {
		return currentSection;
	}
	
	public function back():Void{
		changeSection(String(history.pop()));
	}
}